home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / CC_C / 0151.ZIP / TWIDANSI.C < prev    next >
C/C++ Source or Header  |  1985-08-03  |  3KB  |  145 lines

  1.  
  2. #define RIGHT 79        /* number of columns (0 - N) */
  3. #define TOP 24            /* number of lines  (0 - N) */
  4. #define CAR_LENGTH 24
  5. #define OBSTACLE 60
  6. #define WHERE 49
  7. #define RATIO (RIGHT/TOP)
  8. #define BOX_TOP 3
  9.  
  10. /* Note 20 Jun 85 ... no excuses for the code. Hack the following 
  11. functions to fit your terminal. Tom Jennings */
  12.  
  13. /* Place the cursor at X and Y  */
  14.  
  15. place(x,y)
  16. int x,y;
  17. {
  18.     printf("\033[%d;%df",TOP - x + 1, y + 1);
  19. }
  20. /* Clear the screen */
  21.  
  22. clear() {
  23.     printf("\033[2J");
  24. }
  25.  
  26. /* Waste some time */
  27.  
  28. sleep(n)
  29. int n;
  30. {
  31. long x;
  32.  
  33.     while (n--) for (x= 0L; x < 2000L; x++);
  34. }
  35. /* Plot a character at a location */
  36.  
  37. plot(x,y,c)
  38. int x,y;
  39. char c;
  40. {
  41.     place(x,y);
  42.     printf("%c",c);
  43. }
  44.  
  45. /* and another twiddle. Crash a car into the CRT edges. never stops,
  46. no exit. tj 2/18/81 */
  47.  
  48. main (argc,argv)
  49. int argc;
  50. char **argv;
  51. {
  52.  
  53. int i;
  54.  
  55.     do {
  56.  
  57. /* Erase the screen, draw the road and some things to crash into. */
  58.  
  59.         clear();
  60.         plot_sky();
  61.         place(0,0);
  62.         for (i= 0; i < RIGHT; i++) printf("=");
  63.         for (i= 1; i < BOX_TOP; i++) {
  64.             plot(i,0,'|');
  65.             plot(i,OBSTACLE,'|');        /* draw the sides of */
  66.             plot(i,OBSTACLE + 10,'|');    /* the obstacle */
  67.         }
  68.  
  69.         for (i= OBSTACLE + 1; i < OBSTACLE + 10; i++)
  70.             plot(BOX_TOP,i,'-');        /* plot the top */
  71.  
  72.         for (i= 1; i < (OBSTACLE - CAR_LENGTH); i++) {
  73.             plot_car(i);
  74.         }
  75.  
  76.         plot_eh();
  77.         place(7,WHERE); printf(" Ouch!");
  78.         place(6,WHERE); printf("/     ");
  79.         sleep(8);
  80.         place(7,WHERE); printf("      ");
  81.         place(6,WHERE); printf("      ");
  82.  
  83. /* Now fling the guy out the windshield */
  84.  
  85.         for (i= 0; i < RIGHT - WHERE - 4; i++) {
  86.             plot_guy(i);
  87.         }
  88.         plot_frown();
  89.         place(i / RATIO, 70); printf("splat!");
  90.         sleep(10);
  91.  
  92.     } while (argc < 2);
  93. }
  94.  
  95. /* Plot the car at a location. Dont forget to erase the old one. Try
  96. changing every \\ to \ to see what the car really looks like. */
  97.  
  98. plot_car(i)
  99. int i;
  100. {
  101.     place(5,i); printf("        /------\\        ");
  102.     place(4,i); printf(" ,_____/......|.\\____   ");
  103.     place(3,i); printf(" O   __         |  __O   ");
  104.     place(2,i); printf(" |__/  \\________|_/  \\ ");
  105.     place(1,i); printf("    \\  /          \\  / ");
  106. }
  107. /* Plot the guy flung out the window. */
  108.  
  109. plot_guy(i)
  110. int i;
  111. {
  112.     place((i / RATIO) + 7,i + WHERE); printf("   0  ");
  113.     place((i / RATIO) + 6,i + WHERE); printf("  /-- ");
  114.     place((i / RATIO) + 5,i + WHERE); printf(" /|   ");
  115.     place((i / RATIO) + 4,i + WHERE); printf("                        ");
  116. }
  117.  
  118. /* Plot the sky */
  119.  
  120. plot_sky() {
  121.  
  122.     place(22,50); printf("      \\  |  /     ");
  123.     place(21,50); printf("        _ _       ");
  124.     place(20,50); printf("  --           -- ");
  125.     place(19,50); printf("       \\___/      ");
  126.     place(18,50); printf("   --         --  ");
  127.     place(17,50); printf("       / | \\      ");
  128. }
  129. /* Plot that the sun noticed what happened */
  130.  
  131. plot_eh() {
  132.  
  133.     place(21,40); printf("oops!");
  134.     place(20,40); printf("      \\");
  135.     place(19,50); printf("        ---       ");
  136. }
  137. /* Plot the suns frown. Displeasure at the splat. */
  138.  
  139. plot_frown() {
  140.  
  141.     place(21,40); printf("Yecch!");
  142.     place(21,50); printf("        \\ /       ");
  143.     place(19,50); printf("       /---\\      ");
  144. }
  145.